"""
This file is part of GSBEdit. For copyright and licensing information, please
see gsbedit.py in the GSBEdit base directory.
"""


import os.path
import ConfigParser


class GSBEditConfig:
    def __init__(self, filename):
        self.config = ConfigParser.ConfigParser()
        if os.path.exists(filename):
            self.config.read(filename)
        
        self.filename = filename
    
    
    def get(self, section, option, default=''):
        if self.config.has_option(section, option):
            return self.config.get(section, option)
        else:
            return default
        
    
    def set(self, section, option, value):
        if not(self.config.has_section(section)):
            self.config.add_section(section)
        self.config.set(section, option, value)
        self.flush_to_disk()
    
    
    def flush_to_disk(self):
        output = open(self.filename, 'w')
        self.config.write(output)
        output.close()
        